/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package IO;

import Game.GameConfig;
import java.util.Random;
import java.util.Vector;
import jcgame.Main;
import net.slashie.libjcsi.CSIColor;

/**
 *
 * @author insane
 */
public class Utils {

    private static long start;
    private static Vector<TimeEvents> check;
    private static boolean checkOne = false;

    public static int rand(int min, int max) {
        return min + (new Random()).nextInt(max - min + 1);
    }

    public void timeCheck(String text) {
        if (!GameConfig.getInstance().isTimeCheck()) {
            return;
        }
        if (checkOne) {
            start = System.nanoTime();
            check.add(new TimeEvents(text, 0));
            checkOne = false;
            return;
        }
        long time = System.nanoTime() - start;

        check.add(new TimeEvents(text, time));
    }

    public static void timeStart() {
        if (!GameConfig.getInstance().isTimeCheck()) {
            return;
        }
        check = new Vector();
        start = System.nanoTime();
    }

    public static void seeEvents() {
        if (!GameConfig.getInstance().isTimeCheck()) {
            return;
        }
        for (int i = 0; i < check.size(); i++) {
            TimeEvents te = (TimeEvents) check.elementAt(i);
            Main.csi.print(35, 4 + i, te.getTime() * Math.pow(10, -6) + " - " + te.getText(), CSIColor.WHITE);
            System.out.println(te.getTime() * Math.pow(10, -9) + " - " + te.getText());
        }

        check.clear();
        checkOne = true;
    }

    private class TimeEvents {

        private String text;
        private long time;

        TimeEvents(String text, long time) {
            this.text = text;
            this.time = time;
        }

        /**
         * @return the text
         */
        public String getText() {
            return text;
        }

        /**
         * @return the time
         */
        public long getTime() {
            return time;
        }
    }
}
